﻿using System;
using ebc.coordinator.contract;
using ebc.message.contract;

namespace ebc.coordinator {
    public class Coordinator : ICoordinator {
        private string request;
        private string result;

        public void ProcessCoordinatorRequest(CoordinatorRequest coordinatorRequest) {
            var workerResult = new WorkerResult();

            request = coordinatorRequest.FromSource + "=>InputRequest Coordinator\t<=CoordinatorRequest=>" + Environment.NewLine +
                      "=>OutputRequest Coordiator event OnWorker\t<=WorkerRequest=>" + Environment.NewLine;
            
            OnWorker(new WorkerRequest
            {
                FromSource = request,
                ProcessWorkerResult = r => workerResult = r
            });

            result = workerResult.FromTarget + "=>InputResult Coordinator\t<=WorkerResult=>" + Environment.NewLine +
                     "=>OutputResult Coordinator\t<=CoordinatorResult=>" + Environment.NewLine;
            coordinatorRequest.ShowResult(new CoordinatorResult { FromTarget = result });
        }
    
        public event Action<WorkerRequest> OnWorker;

    }
}